﻿
using System;
using System.Collections.Generic;

namespace LxCFD
{
    public abstract class ValueListMaker
    {
        public abstract class Base<T>
        {
            public List<Value1Base<T>> Value1s = new List<Value1Base<T>>();
            public List<Value2Base<T>> Value2s = new List<Value2Base<T>>();
            public void AddValueProvider(ValueBase<T> valueProvider)
            {
                if (valueProvider is Value1Base<T> value1)
                {
                    add1Provider(value1);
                }
                else if (valueProvider is Value2Base<T> value2)
                {
                    add2Provider(value2);
                }
                else
                {
                    LxConsole.Error("未知ValueProvider数据类型");
                }
            }
            protected void add1Provider(Value1Base<T> value1)
            {
                if (value1.IsEqual0())
                {
                }
                else if (value1 is Value1List.Base<T> vlist)
                {
                    foreach (var l in vlist.Value1s)
                    {
                        Value1s.Add(l);
                    }
                }
                else
                {
                    Value1s.Add(value1);
                }
            }
            protected void add2Provider(Value2Base<T> value2)
            {
                if (value2 is Value2List.Base<T> vlist)
                {
                    foreach (var l in vlist.Value1s)
                    {
                        Value1s.Add(l);
                    }
                    foreach (var l in vlist.Value2s)
                    {
                        Value2s.Add(l);
                    }
                }
                else
                {
                    Value2s.Add(value2);
                }
            }
            public virtual ValueBase<T> MakeValueList()
            {
                throw new NotImplementedException();
            }

        }
        public class Double : Base<double>
        {
            public override ValueBase<double> MakeValueList()
            {
                if (Value2s.Count == 0)
                {
                    if (Value1s.Count == 0)
                    {
                        return new Value1Const.Double(0);
                    }
                    else if (Value1s.Count == 1)
                    {
                        return Value1s[0];
                    }
                    else
                    {
                        return new Value1List.Double() { Value1s = this.Value1s };
                    }
                }
                else
                {
                    if (Value2s.Count == 1 && Value1s.Count == 0)
                    {
                        return Value2s[0];
                    }
                    else
                    {
                        return new Value2List.Double() { Value1s = this.Value1s, Value2s = this.Value2s };
                    }
                }
            }

        }
        public class Vector : Base<Vector3d>
        {
            public override ValueBase<Vector3d> MakeValueList()
            {
                if (Value2s.Count == 0)
                {
                    if (Value1s.Count == 0)
                    {
                        return new Value1Const.Vector(new Vector3d(0,0,0));
                    }
                    else if (Value1s.Count == 1)
                    {
                        return Value1s[0];
                    }
                    else
                    {
                        return new Value1List.Vector() { Value1s = this.Value1s };
                    }
                }
                else
                {
                    if (Value2s.Count == 1 && Value1s.Count == 0)
                    {
                        return Value2s[0];
                    }
                    else
                    {
                        return new Value2List.Vector() { Value1s = this.Value1s, Value2s = this.Value2s };
                    }
                }
            }
        }
    }
}
